﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace B4Deal.Models
{
    public class DashBoard
    {
        private double totalSales;

        public double TotalSales
        {
            get { return totalSales; }
            set { totalSales = value; }
        }
        private int totalOrder;

        public int TotalOrder
        {
            get { return totalOrder; }
            set { totalOrder = value; }
        }
        private int customer;

        public int Customer
        {
            get { return customer; }
            set { customer = value; }
        }

        public DashBoard()
        {
            using (var db = new B4Deal_DataEntities())
            {
                totalSales = 0;
                var temp = db.DONHANGs.ToList();
                totalOrder = temp.Count;
                Customer = db.TAIKHOANs.ToList().Count;
                foreach (var item in temp)
                {
                    var sale = db.KHUYENMAIs.Where(o => o.MaKM == item.KhuyenMai).ToList()[0];
                    totalSales += Convert.ToInt32(item.SoLuong * sale.DonGiaMoi);
                }
            }
        }
    }
}